home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-04-16 | 5.2 KB | 141 lines | [TEXT/CWIE] |
- // IAStorable.h -- Some base classes for objects that may reside in a IAStorage.
- // Copyright: © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
-
-
- #pragma once
- #ifndef IAStorable_h
- #define IAStorable_h
-
- #pragma import on
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=power
- #endif
-
- #include "IAStorage.h"
-
- #pragma IA_BEGIN_EXPORTS
-
- // the base class for storable objects
- class IAStorable : public IAObject {
- public:
- IA_INLINE ~IAStorable() IA_INLINE_DEF() // no-op dtor def
- // returns a copy of an object & any memory it points to
- virtual IAStorable* DeepCopy() const = 0;
- // returns the number of bytes in an objects serialization
- virtual IABlockSize StoreSize() const = 0;
- // serializes the object to output, writing StoreSize() bytes to output
- virtual void Store(IAOutputBlock* output) const = 0;
- // deserializes and returns a new object -- reading StoreSize() bytes from input
- virtual IAStorable* Restore(IAInputBlock* input) const = 0;
- protected:
- // methods to simplify subclassing
- // these are called on a new instance to fill in its slots
- virtual void DeepCopying(const IAStorable* source); // no-op impl
- virtual void Restoring(IAInputBlock* input, const IAStorable* proto);// no-op impl
- };
-
- /*
-
- /// implementations of DeepCopy() and Restore() should work as follows:
-
- IAStorable* SubClass::DeepCopy() const {
- SubClass* sub = new SubClass; // allocate instance
- sub->DeepCopying(this); // copy slots
- return sub; // return it
- }
- void SubClass::DeepCopying(const IAStorable* source) {
- SuperClass::DeepCopying(source); // copy super slots
- // ... copy subclass slots from source ...
- }
- */
-
- // a subclass for IAStorable's which may be sorted
- class IAOrderedStorable : public IAStorable {
- public:
- IA_INLINE ~IAOrderedStorable() IA_INLINE_DEF() // no-op dtor definition
- // returns true iff and object belongs before neighbor
- virtual bool LessThan(const IAOrderedStorable* neighbor) const = 0;
- // returns true iff an object is equal to neighbor
- virtual bool Equal(const IAOrderedStorable* neighbor) const = 0;
- };
-
-
- // IAOrderedStorableSet: a sorted set of IAOrderedStorable's
-
- class IAOrderedStorableIterator : public IAObject {
- public:
- IA_INLINE ~IAOrderedStorableIterator() IA_INLINE_DEF()// no-op dtor def
- // Advances the iterator to the next entry in the set and returns it.
- // Returns NULL at the end of the set.
- // Note: this returns a DeepCopy() of the object. Clients must delete.
- virtual IAOrderedStorable* Next() = 0;
- };
-
- // When cloneStoreStream set true, OrderedStorableSets will use cloned StoreStreams. false by default.
-
- extern bool IACloneOSSetStoreStreams;
-
- class IAOrderedStorableSet : public IAObject {
- public:
- IA_INLINE ~IAOrderedStorableSet() IA_INLINE_DEF()// no-op dtor def
- // initializes a new, empty IAOrderedStorable rooted at the named block, leaving it open.
- // a cloned IAStoreStream may be requested to improve threaded throughput
- virtual void Initialize(IAStorage* storage, IABlockID block,
- bool cloneStoreStream = IACloneOSSetStoreStreams) = 0;
- // flushes any cached changes to disk -- should be called before Commit()
- virtual void Flush() = 0;
- // purges any cached data from memory
- virtual void Purge() = 0;
- // opens an existing IAOrderedStorable rooted at the named block
- // a cloned IAStoreStream may be requested to improve threaded throughput
- virtual void Open(IAStorage* storage, IABlockID block,
- bool writable = true,
- bool cloneStoreStream = IACloneOSSetStoreStreams) = 0;
- // frees all storage associated with the set
- virtual void Destroy() = 0;
-
- // puts an object into the set, replacing any there. object is destroyed.
- virtual bool Put(IAOrderedStorable* obj) = 0;
- // gets an objects from the set, if any such exists, returning a DeepCopy().
- virtual IAOrderedStorable* Get(const IAOrderedStorable* key) = 0;
- // removes an object from the set, if any
- virtual bool Remove(const IAOrderedStorable* key) = 0;
-
- // returns the number of entries in the set
- virtual uint32 Count() = 0;
- // returns the total number of bytes of storage allocated by the set
- virtual uint32 TotalSize() = 0;
-
- // creates an iterator positioned before the first element
- virtual IAOrderedStorableIterator* MakeIterator() = 0;
- // creates an iterator positioned at or after the named element
- virtual IAOrderedStorableIterator* MakeIterator(const IAOrderedStorable* key) = 0;
-
- // returns an estimate of the fraction of the set which lies before the named key.
- // this is useful (with TotalSize()) for estimating the cost of range iteration.
- virtual float PositionEstimate(const IAOrderedStorable* key) = 0;
-
- // in the debug libraries, prints some info about the set to the standard output
- virtual void ReportStats();
- // Get the lock or mutex for committing the entire storage as one transaction
- virtual IAMutex* GetMutex() = 0;
- };
-
- IAExceptionCode OrderedStorableSetEntryTooBig = 'VSBE';
-
- // Returns an instance of the default implementation of IAOrderedStorableSet -- a B-Tree.
- // 'proto' is used to call Restore(). It is deleted when the set is deleted.
- IAOrderedStorableSet* IAMakeOrderedStorableSet(IAOrderedStorable* proto);
-
- extern uint32 OrderedStorableSetType;
-
- #pragma IA_END_EXPORTS
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=reset
- #endif
-
- #pragma import reset
- #endif
-